#coding:utf-8
from google.appengine.ext import db
from lib.models import Course
from lib.models import Grade
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
import os
import cgi

class MainPage(webapp.RequestHandler):
    def get(self):
        sept = Grade.all().filter("sid =", self.request.get('sid')[-5:]).filter('period =', u"ΣΕΠΤ")
        febr = Grade.all().filter("sid =", self.request.get('sid')[-5:]).filter('period =', u"ΦΕΒΡ")
        june = Grade.all().filter("sid =", self.request.get('sid')[-5:]).filter('period =', u"ΙΟΥΝ")
#        query.order("-period")
#        query.order("-added_results_on")
        template_values = {
                "title":cgi.escape(self.request.get('sid')),
                "febr":febr,
                "sept":sept,
                "june":june,
                }
        path = os.path.join(os.path.dirname(__file__), '../templates/student.html')
        self.response.out.write(template.render(path, template_values))

application = webapp.WSGIApplication(
                                     [('/student', MainPage)],
                                     debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
